/**
 * @format
 * @Author: TC
 * @Date: 2025-09-13 22:03:50
 * @Last Modified by: TC
 * @Last Modified time: 2025-09-14 16:09:14
 */

import { _decorator, Component, easing, Node, tween, v3 } from "cc";
import { BaseComponent } from "db://assets/FrameWork/Module/Component/BaseComponent";
const { ccclass, property } = _decorator;

/**
 * 打地鼠游戏背景
 */
@ccclass("MoleGameBg")
export class MoleGameBg extends BaseComponent {
    @property(Node)
    hill0: Node = null;
    @property(Node)
    hill1: Node = null;
    @property(Node)
    hill2: Node = null;
    @property(Node)
    cloud: Node = null;
    @property(Node)
    floor: Node = null;

    @property(Node)
    rainbow: Node = null;
    @property(Node)
    light: Node = null;

    private canTouch: boolean = true;

    protected init(): void {
        super.init();
        tween(this.light).by(25, { angle: -360 }).repeatForever().start();
        tween(this.rainbow)
            .to(15, { position: v3(255, 515, 0) })
            .to(15, { position: v3(55, 515, 0) })
            .union()
            .repeatForever()
            .start();
    }

    protected addUIEvent(): void {
        super.addUIEvent();
        // return;
        this.node.on(Node.EventType.TOUCH_START, this._onTouchBegin, this);
    }

    /**
     * 点击节点
     * @returns
     */
    private _onTouchBegin(): void {
        if (!this.canTouch) return;
        this.canTouch = false;
        this.scheduleOnce(() => {
            this.canTouch = true;
        }, 0.8);

        tween(this.hill0).stop();
        this.hill0.setScale(1, 1, 1);
        tween(this.hill0)
            .to(0.3, { scale: v3(1, 0.7, 1) })
            .to(0.3, { scale: v3(1, 1, 1) })
            .start();

        tween(this.hill1).stop();
        this.hill1.setScale(1, 1, 1);
        tween(this.hill1)
            .to(0.4, { scale: v3(1, 0.8, 1) })
            .to(0.4, { scale: v3(1, 1, 1) })
            .start();

        tween(this.hill2).stop();
        this.hill2.setScale(1, 1, 1);
        tween(this.hill2)
            .to(0.3, { scale: v3(1, 0.8, 1) })
            .to(0.3, { scale: v3(1, 1, 1) })
            .start();

        tween(this.cloud).stop();
        this.cloud.setScale(1, 1, 1);
        tween(this.cloud)
            .to(0.4, { scale: v3(1, 0.9) })
            .to(0.4, { scale: v3(1, 1, 1) })
            .start();

        tween(this.floor).stop();
        this.floor.setScale(1, 1, 1);
        tween(this.floor)
            .to(0.35, { scale: v3(1, 0.98) })
            .to(0.35, { scale: v3(1, 1, 1) })
            .start();
    }
}
